#region using
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion

namespace pong
{
    public static class cCamara
    {
        
        public static Matrix view;
        public static Matrix projection;
        public static Matrix world;
        public static float ratio = 640 / 480;
        private static float nearClip = 1.0f;
        private static float farClip = 1000.0f;
        private static float rotationSpeed = 1f / 160f;
        private static float forwardSpeed = 50f / 60f;
        public static Vector3 posicion;
        private static float fov = MathHelper.PiOver4;
        private static float yaw=0;
        private static float pitch=0;
        private static Vector3 target=Vector3.Zero;
        public static double angulo=Math.PI;

        internal static void Initialize(Vector3 _posicion, Vector3 _target)
        {
            posicion = _posicion;
            target = _target;
            
            
            
            view = Matrix.CreateLookAt(_posicion, _target, Vector3.Up);
            projection = Matrix.CreatePerspectiveFieldOfView(fov, ratio, nearClip, farClip);
            world = Matrix.Identity;


            Vector3 movement = Vector3.Zero;

            Matrix rotationMatrix = Matrix.CreateRotationY(yaw) * Matrix.CreateRotationX(pitch);
            Vector3.Transform(ref movement, ref rotationMatrix, out movement);
            posicion += movement;
            view = Matrix.CreateLookAt(posicion, target, Vector3.Up);
            projection = Matrix.CreatePerspectiveFieldOfView(fov, ratio, nearClip, farClip);
            world = Matrix.Identity; 


            

        }


                
        public static void update(Vector3 _target)
        {



            KeyboardState state = Keyboard.GetState();
            Vector3 movement = Vector3.Zero;



            //movement
            if (state.IsKeyDown(Keys.Z))
            {
                angulo += 0.001f;
            }
            if (state.IsKeyDown(Keys.C))
            {
                angulo -= 0.001f;
            }
/*
            
            if (state.IsKeyDown(Keys.Up))
            {
                movement.Z -= forwardSpeed;
            }
            if (state.IsKeyDown(Keys.Down))
            {
                movement.Z += forwardSpeed;
            }
            if (state.IsKeyDown(Keys.W))
            {
                movement.Y += forwardSpeed;
            }
            if (state.IsKeyDown(Keys.S))
            {
                movement.Y -= forwardSpeed;
            }
            //lock sides            
            if (state.IsKeyDown(Keys.Left))
            {
                yaw += rotationSpeed;
            }
            if (state.IsKeyDown(Keys.Right))
            {
                yaw -= rotationSpeed;
            }

            //look up and down
            if (state.IsKeyDown(Keys.Q))
            {
                pitch -= rotationSpeed;
            }
            if (state.IsKeyDown(Keys.E))
            {
                pitch += rotationSpeed;
            }
 */
            angulo += 0.0001f;
            posicion.X = (float)Math.Cos(angulo) * 50.0f;
            posicion.Z = (float)Math.Sin(angulo) * 50.0f;


            Matrix rotationMatrix = Matrix.CreateRotationY(yaw) * Matrix.CreateRotationX(pitch);
            Vector3.Transform(ref movement, ref rotationMatrix, out movement);
            posicion += movement;
            view = Matrix.CreateLookAt(posicion, _target, Vector3.Up);
            projection = Matrix.CreatePerspectiveFieldOfView(fov, ratio, nearClip, farClip);
            world = Matrix.Identity; 

        }

    }
}